//
//  AllMyOrderViewController.m
//  shopping
//
//  Created by 马田成 on 2017/8/31.
//  Copyright © 2017年 qianyi. All rights reserved.
//

#import "AllMyOrderViewController.h"
#import "MineOrderNoramTableViewCell.h"
@interface AllMyOrderViewController ()<UITableViewDelegate, UITableViewDataSource>

{
    
    float priceAll;
    float numAll;
    
    
}


@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSMutableArray *dataArr;

@end

@implementation AllMyOrderViewController
//全部订单
- (void)viewDidLoad {
    [super viewDidLoad];
    [self creationView];
    [self regeditCell];
    
    
    // Do any additional setup after loading the view.
}
- (void)creationView{

    self.tableView = [[UITableView alloc] init];
    self.tableView.frame = CGRectMake(0, 0, DEF_SCREEN_WIDTH, DEF_SCREEN_HEIGHT - 64 - 40);
    self.tableView.tableFooterView = [[UITableView alloc] initWithFrame:CGRectZero];
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
}

- (void)zj_viewDidLoadForIndex:(NSInteger)index {
    //    NSLog(@"%@",self.view);
    //    NSLog(@"%@", self.zj_scrollViewController);
    
    
}
- (void)zj_viewWillAppearForIndex:(NSInteger)index {
    // NSLog(@"viewWillAppear------");
    
    [self creationDate];
    
}


- (void)zj_viewDidAppearForIndex:(NSInteger)index {
    // NSLog(@"viewDidAppear-----");
    
}
- (void)regeditCell{
    
    
    
    [self.tableView registerNib:[UINib nibWithNibName:@"MineOrderNoramTableViewCell" bundle:nil] forCellReuseIdentifier:@"MineOrderNoramTableViewCell"];
    

    
}
- (void)creationDate{
    
    _dataArr = [[NSMutableArray alloc] init];
    
    NSMutableDictionary *productParams=[[NSMutableDictionary alloc]init];
    NSString *token = [PublicFunction getConfigWithKey:@"token"];
    //NSString *token = @"33232cdfabf7e00edbcfe513c73b2809d663";
    
    [productParams setValue:token forKey:@"token"];
    [productParams setValue:@"999" forKey:@"status"];
    
    
    [[MNetworkHandler sharedInstance]conURL:adminorderGetOrderByStatus networkType:NetWorkPOST params:productParams delegate:nil showHUD:NO successBlock:^(id returnData) {
        
        
        if ([[returnData objectForKey:@"code"]intValue]==1) {
            
            _dataArr = [returnData objectForKey:@"data"];
 
            [self.tableView reloadData];
            
            
        }
        
        else {
            
            [PublicFunction showAlert:nil message:[returnData objectForKey:@"msg"] duration:5.0f];
            
        }
        
    } failureBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
        
//        [PublicFunction showAlert:nil message:@"没有连接网络" duration:10.0f];
        
    }];
    
    
}

#pragma mark - ---------- Section的数量 ----------
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}
#pragma mark - ---------- 每个Section的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10;
}

//section 不随tableView滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    
    if (scrollView == self.tableView)
        
    {
        
        CGFloat sectionHeaderHeight = 64; //header高度
        
        if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) {
            
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
            
        } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
            
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
            
        }
        
    }
    
    
    
}


#pragma mark - ---------- Cell的数量 ----------
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    
    return self.dataArr.count;
    
}

#pragma mark - ---------- 每个Cell的高度 ----------
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    NSMutableArray *a = [self.dataArr[indexPath.row] valueForKey:@"goodslist"];
    
    return (250 + 100*a.count);
    //  return 250 + 200;
    
}
#pragma mark - ---------- 每个Cell的内容 ----------
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    MineOrderNoramTableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"MineOrderNoramTableViewCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    NSMutableDictionary *dic = self.dataArr[indexPath.row];
    cell.shopName.text = [dic objectForKey:@"shopName"];
    cell.zongJia.text = [dic objectForKey:@"totalMoney"];
    cell.arrOfPic = [dic objectForKey:@"goodslist"];
    cell.chaKanWLBtn.hidden = YES;
    cell.yanChangBtn.hidden = YES;
    
    
    if ([[dic objectForKey:@"orderStatus"] isEqualToString:@"-2"]) {
        [cell.sureBtn setTitle:@"请付款" forState:UIControlStateNormal];
        
    }else if ([[dic objectForKey:@"orderStatus"] isEqualToString:@"3"]) {
        [cell.sureBtn setTitle:@"请确认收货" forState:UIControlStateNormal];
        
    }else if ([[dic objectForKey:@"orderStatus"] isEqualToString:@"4"]) {
        [cell.sureBtn setTitle:@"评价" forState:UIControlStateNormal];
        
    }else if ([[dic objectForKey:@"orderStatus"] isEqualToString:@"0"] ||[[dic objectForKey:@"orderStatus"] isEqualToString:@"1"] ||[[dic objectForKey:@"orderStatus"] isEqualToString:@"2"]) {
        [cell.sureBtn setTitle:@"提醒发货" forState:UIControlStateNormal];
        
    }else if ([[dic objectForKey:@"orderStatus"] isEqualToString:@"-1"] ||[[dic objectForKey:@"orderStatus"] isEqualToString:@"-6"] ||[[dic objectForKey:@"orderStatus"] isEqualToString:@"-7"]) {
        [cell.sureBtn setTitle:@"已取消" forState:UIControlStateNormal];
        
    }else {
    
        [cell.sureBtn setTitle:@"拒收、退款" forState:UIControlStateNormal];

    }
    
    
    
    return cell;
    
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
